package com.tz.common.util;

import android.util.Log;

/**
 * 数据类型安全转换
 * Created by chris on 15/7/3.
 */
public class NumberFormatUtil {

    private static final String TAG = "NumberFormatUtil";

    public static long parseLong(String s) {
        long value = 0;
        try {
            value = Long.parseLong(s);
        } catch (Exception e) {
            Log.e(TAG, e.toString());
        }
        return value;
    }

    public static long parseLong(String s, long defaultValue) {
        long value = 0;
        try {
            value = Long.parseLong(s);
        } catch (Exception e) {
            value = defaultValue;
            Log.e(TAG, e.toString());
        }
        return value;
    }

    public static int parseInt(String s) {
        int value = 0;
        try {
            value = Integer.parseInt(s);
        } catch (Exception e) {
            Log.e(TAG, e.toString());
        }
        return value;
    }

    public static int parseInt(String s, int defaultValue) {
        int value = 0;
        try {
            value = Integer.parseInt(s);
        } catch (Exception e) {
            value = defaultValue;
            Log.e(TAG, e.toString());
        }
        return value;
    }

    public static double parseDouble(String s) {
        double value = 0.0;
        try {
            value = Double.parseDouble(s);
        } catch (Exception e) {
            Log.e(TAG, e.toString());
        }
        return value;
    }

    public static double parseDouble(String s, double defaultValue) {
        double value = 0.0;
        try {
            value = Double.parseDouble(s);
        } catch (Exception e) {
            value = defaultValue;
            Log.e(TAG, e.toString());
        }
        return value;
    }

}
